--
-- Author: shunguo.chen
-- Date: 2017-08-31 17:26:11
--
-- UserBaseInfo 通用玩家基础信息

local AvatarInfo = import(".AvatarInfo")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, AvatarInfo)

function ClassRef:ctor(data)
    self.super.ctor(self, data)

    self.online = true
    self.partners = {}
end

-- int32 uid = 1;
-- string name = 2;
-- int32 lv = 3;
-- int32 raceID = 4; // 种族
-- int32 classID = 5; // 职业
-- int32 specialistID = 6; // 专精ID
-- int32 gender = 7; // 性别
-- int32 faceID = 8; // 脸型
-- int32 hairID = 9; // 发型
-- int32 hairColorID = 10; // 发色
-- repeated int32 fashionIDs = 31; // 装备幻化外显
-- int32 mountID = 40; // 坐骑
-- int32 badgeID = 50; // 称号勋章
-- string guildName = 60; // 公会名
-- string guildID = 61; // 公会ID
-- int32 combatPower = 70; //战斗力
-- int32 serverID = 80; // server ID
function ClassRef:read(data)
    self.super.read(self, data)

	self.uid = data.uid or 0
	self.name= data.name or ""
	self.level = data.lv or data.level or 1
    self.lv = self.level    -- 兼容lv

    self.sex = self.gender      -- 兼容sex

    self.specialistID = data.specialistID or 101

    self.titleID = data.titleID or 0
    self.guildName = data.guildName or ""
    self.guildID = data.guildID or ""
    self.combatPower = data.combatPower or 0
    self.serverID = data.serverID or 0

    self:updatePartner(data)
    -- self.PartnerQuality = data.PartnerQuality or 1

    self.mainTaskID = data.mainTaskID
	-- dump(self, "BaseInfo.read")
    self.speed = data.Speed -- 不能设置为0，无值的时候默认为空，setSpeed的时候会把空值排除掉
end

function ClassRef:updatePartner(value)
    local ps = {}
    local partners = rawget(value, "partners")
    if partners then
        for k , v in pairs(partners) do
            -- ps[v.ID] = {raceId = v.RaceId, combatPower = v.CombatPower}
            table.insert(ps, {ID = v.ID, RaceId = v.RaceId, CombatPower = v.CombatPower, Lv = v.Lv})
        end
    end
    self.partners = ps
end

-- 是否是机器人，uid < 0
function ClassRef:isRobot()
    return self.uid < 0
end

function ClassRef:isMe()
    -- UD未初始化，认为就是自己（登录选角创角）
    if UD:isInit() then
        return self.uid == UD:getUid()
    else
        return true
    end
end

-- 天赋名字+职业名字，如 火焰法师（奇葩的取配置方式）
function ClassRef:getDuty()
    local ary = string.split( self.specialistID, "0" )
    local str = L("class_" .. ary[1] .. "_" .. ary[2] ) .. L("class_"..self.classID)
    return str
end

-- 获取专精图标
function ClassRef:getSpecialistIcon()
    local conf = GD:getSpec_typeConfig(self.specialistID)
    if conf then
        return Res.SpecTypeIconPath .. conf.jobType .. ".png"
    end
end

-- 获取职业图标
function ClassRef:getClassIcon()
    return GD:getClassIcon( self.classID, 2 )
end

function ClassRef:setOnline( isOnline )
    self.online = isOnline
end

function ClassRef:cloneAvatarParams(data)
    self.super.read(self, data)
end

function ClassRef:clone()
    local info = ClassRef.new()
    
    info:read(self)

    return info
end

function ClassRef:getUid()
    return self.uid
end

function ClassRef:getName()
    return self.name
end

return ClassRef
